package com.atguigu.study.listener;

import cn.hutool.core.util.IdUtil;
import dev.langchain4j.model.chat.listener.ChatModelErrorContext;
import dev.langchain4j.model.chat.listener.ChatModelListener;
import dev.langchain4j.model.chat.listener.ChatModelRequestContext;
import dev.langchain4j.model.chat.listener.ChatModelResponseContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

/**
 * @author Marco
 * @Description
 * @date 2025/8/18 21:17
 * @email 3293336923@qq.com
 */
@Slf4j
@Configuration
public class TestModelListener   implements ChatModelListener {

    @Override
    public void onRequest(ChatModelRequestContext requestContext) {

        String uuidValue = IdUtil.simpleUUID();
        requestContext.attributes().put("TraceID" , uuidValue);
        log.info("请求参数 requestContext:{}",requestContext+"\t"+uuidValue);
    }

    @Override
    public void onResponse(ChatModelResponseContext responseContext) {

        Object object = responseContext.attributes().get("TraceID");
        log.info("返回结果responseContext:{}",object);
    }

    @Override
    public void onError(ChatModelErrorContext errorContext) {

        log.error("请求异常ChatModelErrorContext:{}",errorContext);
    }
}
